import { runCommand } from ".";

export default {
    canUndo: true,
    execute: (context, options, isUndo) => {
        runCommand(context, options, isUndo, (sheet, options) => {
            const { selections } = options;
            const topRow = sheet.getViewportTopRow(1);
            sheet.suspendPaint();
            selections.forEach(range => {
                const {row,rowCount} = range;
                for(let r=0;r<rowCount;r++){
                    sheet.setRowVisible(row+r, true);
                }
                if(rowCount===1 && row===topRow){
                    sheet.setRowVisible(row-1, true);
                    sheet.showRow(row-1, GC.Spread.Sheets.VerticalPosition.top);
                }
            })
            sheet.resumePaint();
        })  
    }
};